package com.agino;

import org.apache.commons.math3.stat.StatUtils;
import org.nfunk.jep.ParseException;
import org.nfunk.jep.function.PostfixMathCommand;

import java.util.Stack;

/**
 * @author agino
 * @version 1.0
 * @date 2022/8/1 16:37
 */
public class MaxFunction extends PostfixMathCommand {

    public MaxFunction() {
        super();
        numberOfParameters = 1;
    }

    @Override
    public void run(Stack stack) throws ParseException {
        checkStack(stack);
        double[] params = (double[]) stack.pop();
        double max = StatUtils.max(params);
        stack.push(max);
    }
}
